//
//  BTChatBarToolView.m
//  BaiTengIM
//
//  Created by awh on 2019/6/26.
//  Copyright © 2019年 awh. All rights reserved.
//

#import "BTChatBarToolView.h"

#import "BTChatBarToolViewCell.h"
#import "BTChatBarToolModel.h"

@interface BTChatBarToolView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property(nonatomic, strong) NSArray<BTChatBarToolModel *> *dataSources;

@end

@implementation BTChatBarToolView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupDataSources];
    [self.collectionView registerNib:[UINib nibWithNibName:[BTChatBarToolViewCell cellIdentifier] bundle:nil] forCellWithReuseIdentifier:[BTChatBarToolViewCell cellIdentifier]];
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor=KHEXCOLOR(@"#EDEDED");
    self.collectionView.delegate = self;
}

- (void)setupDataSources {
    BTChatBarToolModel *image = [BTChatBarToolModel toolWithTitleName:@"图片" imageName:@"icon_lt_pic" operation:^{
        
    }];
    BTChatBarToolModel *camera = [BTChatBarToolModel toolWithTitleName:@"拍摄" imageName:@"icon_lt_photo" operation:^{
        
    }];
//    BTChatBarToolModel *BusinessCard = [BTChatBarToolModel toolWithTitleName:@"名片" imageName:@"icon_lt_photo" operation:^{
//
//    }];
    _dataSources = @[image, camera];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return  self.dataSources.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    BTChatBarToolViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[BTChatBarToolViewCell cellIdentifier] forIndexPath:indexPath];
    cell.tool = self.dataSources[indexPath.item];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.delegate && [self.delegate respondsToSelector:@selector(toolView:didSelectedAtItem:)]) {
        [self.delegate toolView:self didSelectedAtItem:indexPath.item];
    }
}




@end
